/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.config.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.punish.config.dto.*;
import com.icinfo.cloud.provider.punish.config.service.IConfigOrgRegulatoryDiscretionRuleHisService;
import com.icinfo.cloud.provider.punish.config.service.IConfigOrgRegulatoryDiscretionService;
import com.icinfo.cloud.provider.punish.config.vo.ConfigOrgRegulatoryDiscretionDetailVo;
import com.icinfo.cloud.provider.punish.config.vo.ConfigOrgRegulatoryDiscretionPageVo;
import com.icinfo.cloud.provider.punish.config.vo.ConfigOrgRegulatoryDiscretionRuleVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 部门事项自由裁量配置-控制层
 *
 * @author Junfeng.Chen
 * @date 2024/1/30 15:42
 **/
@Resource
@RestController
@RequestMapping("/punish/config/discretion")
public class ConfigOrgRegulatoryDiscretionController extends BaseController {
    @Resource
    private IConfigOrgRegulatoryDiscretionService configOrgRegulatoryDiscretionService;
    @Resource
    private IConfigOrgRegulatoryDiscretionRuleHisService configOrgRegulatoryDiscretionRuleHisService;

    /**
     * 分页查询自由裁量事项列表
     *
     * @param dto 分页查询参数
     * @return 分页查询出的结果
     */
    @PostMapping("/currentOrg/regulatoryDiscretionPage")
    public Result<PageResponse<ConfigOrgRegulatoryDiscretionPageVo>> regulatoryDiscretionPage(@Validated @RequestBody ConfigOrgRegulatoryDiscretionPageDto dto) {
        return Result.success(configOrgRegulatoryDiscretionService.regulatoryDiscretionPage(dto));
    }

    /**
     * 保存配置自由裁量
     *
     * @param dto 保存参数
     * @return 无
     */
    @PostMapping("/currentOrg/save")
    public Result<Object> save(@Validated @RequestBody ConfigOrgRegulatoryDiscretionSaveDto dto) {
        configOrgRegulatoryDiscretionService.save(dto);
        return Result.success("保存成功");
    }

    /**
     * 查询当前部门配置详情，若没有也会返回空数组数据
     *
     * @param regulatoryCatalogId 事项唯一id
     * @return 无
     */
    @GetMapping("/currentOrg/detail")
    public Result<ConfigOrgRegulatoryDiscretionDetailVo> detail(@RequestParam("regulatoryCatalogId") String regulatoryCatalogId) {
        return Result.success(configOrgRegulatoryDiscretionService.detail(regulatoryCatalogId));
    }

    /**
     * 当前部门事项选择启用标准
     *
     * @param dto 事项唯一id
     * @return 无
     */
    @PostMapping("/currentOrg/chooseDiscretionType")
    public Result<Object> chooseDiscretionType(@RequestBody @Validated RegulatoryChooseDiscretionTypeDto dto) {
        configOrgRegulatoryDiscretionService.chooseDiscretionType(dto);
        return Result.success("操作成功");
    }

    /**
     * 根据事项唯一id和当事人信息查询该事项的违法情形列表
     *
     * @param dto 请求参数
     * @return 无
     */
    @GetMapping("/getRuleListByRegulatoryAndParty")
    public Result<List<ConfigOrgRegulatoryDiscretionRuleVo>> getRuleListByRegulatoryAndParty(@Validated DiscretionRuleListByRegulatoryAndPartyDto dto) {
        return Result.success(configOrgRegulatoryDiscretionService.getRuleListByRegulatoryAndParty(dto));
    }

    /**
     * 根据busId和当事人信息查询该事项的违法情形列表
     *
     * @param dto 请求参数
     * @return 无
     */
    @GetMapping("/getRuleListByBusIdAndParty")
    public Result<List<ConfigOrgRegulatoryDiscretionRuleVo>> getRuleListByBusIdAndParty(@Validated DiscretionRuleListByBusIdAndPartyDto dto) {
        return Result.success(configOrgRegulatoryDiscretionService.getRuleListByBusIdAndParty(dto));
    }

    /**
     * 根据案由和当事人信息查询违法情形列表
     *
     * @param dto 请求参数
     * @return
     */
    @GetMapping("/getRuleListByCaseReasonAndParty")
    public Result<List<ConfigOrgRegulatoryDiscretionRuleVo>> getRuleListByCaseReasonAndParty(@Validated DiscretionRuleListByCaseReasonAndPartyDto dto) {
        return Result.success(configOrgRegulatoryDiscretionService.getRuleListByCaseReasonAndParty(dto));
    }

    /**
     * 获取合并处罚违法情形列表通过案件id
     *
     * @param dto 请求参数
     * @return
     */
    @GetMapping("/getMergeRuleListByCaseId")
    public Result<List<ConfigOrgRegulatoryDiscretionRuleVo>> getMergeRuleListByCaseId(@Validated DiscretionRuleListByCaseDto dto) {
        return Result.success(configOrgRegulatoryDiscretionService.getMergeRuleListByCase(dto));
    }

    /**
     * 校验处罚金额是否满足裁量区间
     * @param dto 请求参数
     * @return
     */
    @GetMapping("/verifyDiscretionAmount")
    public Result<String> verifyDiscretionAmount(CompareSingleDiscretionDto dto) {
        configOrgRegulatoryDiscretionRuleHisService.verifySingleDiscretionAmount(dto);
        return Result.success("操作成功");
    }

}